package com.tianyadu.mmall.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 请求超时处理
 *
 * @author xueyj
 * @date 2019-09-21 21:27
 */
@Slf4j
@Aspect
@Component
public class TimeAspect {

    /**
     * Around环绕通知
     * <p>
     * com.tianyadu.mmall包及所有子包下任何类的任何方法
     *
     * @param pjp
     * @return java.lang.Object
     * @author xueyj
     * @date 2019/9/21-21:28
     */
    //  @Around("execution(public * com.tianyadu.mmall.*(..))")
    // @Around("execution(* com.tianyadu.mmall..*.*(..))")
    @Around("execution(* com.tianyadu.mmall.controller.PersonController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        log.info("time aspect 被调用");
        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            log.info("arg is 【{}】", arg);
        }
        long start = System.currentTimeMillis();
        Object object = pjp.proceed();
        log.info("time aspect 耗时:【{}】", (System.currentTimeMillis() - start));
        log.info("time aspect 调用结束");
        return object;
    }
}